package fr.lip6.move.care

import sdmakerz_v1.coresyntax.generator.interfaces.IContext
import sdmakerz_v1.coresyntax.sDMakerV1.Obj
import sdmakerz_v1.coresyntax.generator.interfaces.IInterfaceData

class CareObjGen {
	private CareGen mainGenerator;
	
	new(CareGen mainGenerator){
		this.mainGenerator= mainGenerator;
	}
	
	def public
	CompileResult compile(IContext context, Obj obj){
	    var CompileResult compileResult= CompileResult::EMPTY_RESULT;
        var newObjName= context.getDiagramRefData().getNewName(obj.name);
        var IInterfaceData interfaceData= null;
        var CharSequence charSequenceResult= null;

		println("for "+obj.name+" newObjName="+newObjName);

        if(newObjName.compareTo(obj.name)==0){
            
            /* On compile un Obj qui n'est pas une reference donc
             * on doit creer l'acteur dans le main. */
           interfaceData= 
           		context.getInterfaceDataByName(obj.type.identifier);
           
           charSequenceResult=
           '''
           Actor «obj.name» = new Actor("«obj.name»", «interfaceData.interfaceID»); 
           actors.add(«obj.name»);
           '''
           
           compileResult= new CompileResult(
           						charSequenceResult,
           						obj.name,
           						false)
		}
		
		return compileResult;
	}
}